﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using FDSimpleModelGenerator.Common.Enums;
using FDSimpleModelGenerator.Entities;
using FDSimpleModelGenerator.Entities.Enums;
using FDSimpleModelGenerator.IServices;

namespace FDSimpleModelGenerator.Services
{
    /// <summary>
    /// 模型生成引擎抽象实现
    /// </summary>
    public abstract class BasicModelGenerateEngine : IModelGenerateEngine
    {
        private readonly IEnumerable<IDataTypeMapperService> _dataTypeMapperServices;

        public BasicModelGenerateEngine(IEnumerable<IDataTypeMapperService> dataTypeMapperServices)
        {
            _dataTypeMapperServices = dataTypeMapperServices;
        }

        /// <summary>
        /// 获取类型映射服务
        /// </summary>
        /// <param name="languageDataType"></param>
        /// <returns></returns>
        public IDataTypeMapperService GeTypeMapperService(LanguageDataType languageDataType)
        {
            return _dataTypeMapperServices.First(d => d.LanguageDataType == languageDataType);
        }

        public abstract string Generate(TableInfo tableInfo, string templateContent, string namespaceName,
            LanguageDataType languageDataType,
            bool propertyFirstCharLower = false);

        public abstract Task<string> GenerateAsync(TableInfo tableInfo, string templateContent, string namespaceName,
            LanguageDataType languageDataType,
            bool propertyFirstCharLower = false);
    }
}
